home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Ken Long / Lightspeed-p-c / About this one.
Encoding:
Text File  |  1994-12-04  |  3.5 KB  |  82 lines  |  [TEXT/EDIT]

  1. LightSpeed - A space flight toy, by Jonathan Birge.  Gotten to run
  2. in Think Pascal and C, and Metrowerks C and Pascal by Kenneth A. Long,
  3. at itty bitty bytes(tm).
  4.  
  5. -------------------------------------------------------------------
  6.  
  7. Each one of these is different.  The Think Pascal was the first one.
  8.  
  9. The Metrowerks Pascal one has a full with direction indicator cross-
  10. hair.
  11.  
  12. Steering is done with the numeric key pad.
  13.  
  14. 4, 7, 8, 9, 6, 3, 2 and 1 all steer.  The 5 key puts the "stick" in
  15. neutral (straight ahead).  The '+' key accelerates by a factor of
  16. .01 and the '-' key reverses that.  The '0' key stops.
  17.  
  18. The 'Q' quits and the space bar fires "photon torpedoes."  I didn't
  19. bothe getting the sound to work on any of them.
  20.  
  21. -------------------------------------------------------------------
  22. "Lightspeed" was a Pascal source sent to me by Jonathan Birge,
  23. in response to a request I made for starfield source.  This was
  24. prompted by seeing a nicely done "space flight" scene in the about
  25. box of his program "Digital Camera."
  26.  
  27. I had no Pascal compiler at the time, so I attempted a C port.  I
  28. got the photons working and the sound, and it made one-pixel stars
  29. that "twinkled" randomly.  The cross-sight worked but key hits did
  30. nothing, except for 'Q'. 
  31.  
  32. Someone on AOL built an application for me with his Pascal compiler
  33. and I saw that the sight did not show on that one, yet the stars
  34. worked as in the included one, here.  I couldn't figure out what was
  35. so bogus about my port.
  36.  
  37. Then I got Think Pascal and thought if I could run it in ThP and
  38. look at the values in the debugger, I could spot the differences in
  39. the Think C debugger and fix it.  But in ThP it would not step.
  40.  
  41. Then I got Code Warrior, which has a great debugger, and I thought
  42. if I could run it in MW Pascal, in the debugger, I could finally get
  43. in to run right in Think C.  No such luck.  Something else was wrong
  44. (which I later figured out, witness the MWP port).
  45.  
  46. Think Pascal is MUCH easier to operate than MWP, although I finally
  47. got it whoopped, too.
  48.  
  49. What finally happened was I did the port all over again, and it ran
  50. even different this time.  But the "Size" variable always came out
  51. with a value of 12 after the initial LoadStars routine ran.  That
  52. variable is in the MakeRect routine, which determines the size of
  53. the star rectangles.  It comes from some math involving random gen.
  54. routines.  So, I determined that the random routines were putting
  55. out something bogus.
  56.  
  57. On closer inspection, I determined the 'extended' type was the bug.
  58. In Think Pascal it's a 16 byte (96 bit) variable.  In Think C it's
  59. a 10 byte (80 bit) struct.  So, any way I tried it I'd either get
  60. compile errors or a crash.
  61.  
  62. So, I got to thinking:  "If the random generted values are 96 bits
  63. in size, for proper running, then why not get it to generate some
  64. that are a lower harmonic of that and store them in a smaller 
  65. variable that I *DO* have (easily)."  Yes, I could do the 80xTo96X
  66. thing (or whatever it is) if I *knew* how - but I don't.  So I have
  67. to settle for the "stop-gap" method.
  68.  
  69. I did, and dumped a few 'abs' calls and sized down the some of the
  70. variables to 'doubles' and I got it working!  Not as cool as the
  71. Think Pascal one, but working just the same.  My deductive reasoning
  72. with no help from anyone (but me) have paid off again.  Lots of real
  73. programmers may look at the C source and think of all sorts of ways
  74. to improve it.  If you do then *please* do!  Then send it to me.
  75.  
  76. Anyway, it's not a perfect port, but HEY!  It's C source!  It does
  77. not run perfectly but it does run!
  78.  
  79. Enjoy!
  80.  
  81. kenlong@netcom.com
  82.